﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;
using Bussiness;
using Entity;
using System.Threading;

namespace UI
{
    public partial class LoginForm : KryptonForm
    {
        private bool isLogined = false;
        private string _UserName = string.Empty;
        private string _Psw = string.Empty;
        public string UserName
        {
            get { return this._UserName; }
        }
        public string Psw
        {
            get { return this._Psw; }
        }

        public LoginForm()
        {
            InitializeComponent();
        }
        private void LoginForm_Load(object sender, EventArgs e)
        {
            this.Tbox_user.Focus();
        }

        private void Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Login_Click(object sender, EventArgs e)
        {
            string userName = Tbox_user.Text.Trim();
            string psw = Tbox_psw.Text.Trim();
            this._UserName = userName;
            this._Psw = psw;
            DialogResult = DialogResult.OK;
            //if (userName != string.Empty && psw != string.Empty)
            //{
            //    bool isSucceed=login(userName, psw);
            //    if (isSucceed)
            //    {
            //        if (!isLogined)
            //        {
            //            this.isLogined = true;
            //            MainForm mf = new MainForm();
            //            mf.Show();
            //        }
            //        this.Visible = false;
            //    }
            //    else
            //    {
            //        MessageBox.Show("用户名或密码不正确！");
            //    }
            //}
            //else
            //{
            //    MessageBox.Show("用户名或密码不能为空！");
            //}
        }
        //private bool login(string userName,string psw)
        //{
        //    bool isSucceed = false;                
        //    AccountManager am = new AccountManager();
        //    EAccount account = am.login(userName, psw);
        //    if (account != null)
        //    {
        //        SessionHelper.CurrentUser.UserName = account.UserName;
        //        SessionHelper.CurrentUser.Role = account.RoleName;
        //        SessionHelper.CurrentUser.Authorities = account.GetAuthorities();
        //        isSucceed = true;
        //    }
        //    return isSucceed;        
        //}

        
    }
}
